//
//  PhysicsDrawer.h
//  Olivia
//
//  Created by 钟昆达 on 13-4-12.
//
//

#ifndef Olivia_PhysicsDrawer_h
#define Olivia_PhysicsDrawer_h

#include "Box2D/Common/b2Draw.h"
#include <vector>

namespace Ogre {
    class ManualObject;
}

class b2Vec2;
class b2Color;

namespace Olivia {
    
    class PhysicsDraw : public b2Draw {
    public:
        PhysicsDraw(Ogre::ManualObject *_prim);
        ~PhysicsDraw();
        
        void DrawPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color &color);
        void DrawSolidPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color &color);
        void DrawCircle(const b2Vec2 &center, float32 radius, const b2Color &color);
        void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);
        
        virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);
        
        virtual void DrawTransform(const b2Transform& xf);
        
        void Render();
    protected:
        Ogre::ManualObject *m_primitives;
        struct Polygon
        {
            int32 v_begin;
            int32 v_count;
            b2Color color;
        };
        struct Circle
        {
            b2Vec2 center;
            float32 radius;
            b2Color color;
        };
        struct Segment
        {
            b2Vec2 p1, p2;
            b2Color color;
        };
        
        typedef std::vector<Polygon> PolygonVec;
        typedef std::vector<Circle> CircleVec;
        typedef std::vector<b2Vec2> VertexVec;
        typedef std::vector<Segment> SegmentVec;
        typedef std::vector<b2Transform> TransformVec;
        
        PolygonVec m_wf_polygons, m_solid_polygons;
        CircleVec m_wf_circles, m_solid_circles;
        VertexVec m_polygon_vertices;
        SegmentVec m_segments;
        TransformVec m_transforms;
        
        int32 m_i_count, m_v_count;
    };
}

#endif
